package com.mxpio.erp.workshop.controller;

import com.mxpio.erp.common.workshop.entity.*;
import com.mxpio.erp.common.workshop.service.ScreenReportService;
import com.mxpioframework.common.vo.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Tag(name = "ScreenReportController", description = "车间生产大屏接口")
@RestController
@RequestMapping("/erp/workshop/screen_report/")
public class ScreenReportController {
	
	@Autowired
	private ScreenReportService screenReportService;


	@GetMapping("workshop_passrate_month/list")
	@Operation(summary = "各车间生产质量情况", description = "各车间生产质量情况", method = "GET")
	public Result<List<VWorkShopPassRateDetail>> workShopPassRateMonthList() {
		List<VWorkShopPassRateDetail> list = screenReportService.workShopPassRateMonthList();
		return Result.OK(list);
	}

	@GetMapping("workshop_pass_year/list")
	@Operation(summary = "生产入库不合格情况", description = "生产入库不合格情况", method = "GET")
	public Result<List<VWorkShopPassRateDetail>> workShopPassYearList() {
		List<VWorkShopPassRateDetail> list = screenReportService.workShopPassYearList();
		return Result.OK(list);
	}
	@GetMapping("purchasein_unqualified_top5/list")
	@Operation(summary = "采购入库不合格情况TOP5", description = "采购入库不合格情况TOP5", method = "GET")
	public Result<List<VPurchaseinInspectUnqualified>> purchaseinUnqualifiedTop5() {
		List<VPurchaseinInspectUnqualified> list = screenReportService.purchaseinUnqualifiedTop5();
		return Result.OK(list);
	}

	@GetMapping("mo_execute_curmon/list")
	@Operation(summary = "统计生产当月(计划完成时间)执行情况，按车间汇总", description = "统计生产当月(计划完成时间)执行情况，按车间汇总", method = "GET")
	public Result<List<VMOExecuteSum>> moExecuteSum() {
		List<VMOExecuteSum> list = screenReportService.moExecuteSum();
		return Result.OK(list);
	}

	@GetMapping("mo_delay_top50/list")
	@Operation(summary = "各车间延期订单信息TOP50", description = "各车间延期订单信息TOP50", method = "GET")
	public Result<Page<VMODelay>> moDelayTop50(Integer pageSize, Integer pageNo) {
		Pageable pageAble = PageRequest.of(pageNo-1, pageSize);
		Page<VMODelay> page = screenReportService.moDelayTop50(pageAble);
		return Result.OK(page);
	}

	@GetMapping("poline_execute_curmon/list")
	@Operation(summary = "统计当月采购订单明细(建议下单时间：时间范围取上个月26号到本月25号) 执行情况汇总", description = "统计当月采购订单明细(建议下单时间：时间范围取上个月26号到本月25号) 执行情况汇总", method = "GET")
	public Result<List<VPODelay>> poExecuteDelaySum() {
		List<VPODelay> list = screenReportService.poExecuteDelaySum();
		return Result.OK(list);
	}

	@GetMapping("poline_execute_delay_detail/list")
	@Operation(summary = "采购订单明细行执行延期列表(建议下单时间：时间范围取上个月26号到本月25号，并按延期天数降序)", description = "采购订单明细行执行延期列表(建议下单时间：时间范围取上个月26号到本月25号，并按延期天数降序)", method = "GET")
	public Result<Page<VPurchaseOrderLineExecDtail>> purchaseOrderLineExecDelayList(Integer pageSize, Integer pageNo) {
		Pageable pageAble = PageRequest.of(pageNo-1, pageSize);
		Page<VPurchaseOrderLineExecDtail> page = screenReportService.purchaseOrderLineExecDelayList(pageAble);
		return Result.OK(page);
	}

	@GetMapping("mo_finish_rate_curmon")
	@Operation(summary = "生产订单完成率(统计当月) 统计生产当月(计划完成时间)", description = "生产订单完成率(统计当月) 统计生产当月(计划完成时间)", method = "GET")
	public Result<VMOCurMonFinishRate> moCurMonFinishRate() {
		VMOCurMonFinishRate curMonFinishRate= screenReportService.moCurMonFinishRate();
		return Result.OK(curMonFinishRate);
	}

	@GetMapping("workshop_finish_rate_curmon/list")
	@Operation(summary = "车间生产订单完成率(统计当月)", description = "车间生产订单完成率(统计当月) 统计生产当月(计划完成时间)", method = "GET")
	public Result<List<VWorkShopCurMonFinishRate>> workShopCurMonFinishRate() {
		List<VWorkShopCurMonFinishRate> vWorkShopCurMonFinishRates = screenReportService.workShopCurMonFinishRate();
		return Result.OK(vWorkShopCurMonFinishRates);
	}
}
